﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using MyMES.Dto;
using MyMES.Infrastructure;
using MyMES.IServices;
using MyMES.Services;
using System.Threading.Tasks;
using VOL.Entity.DomainModels;

namespace VOL.WebApi.Controllers
{
    /// <summary>
    /// 仓库设置控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class WarehouseManagementController : ControllerBase
    {
        /// <summary>
        /// 仓库设置仓储
        /// </summary>
        private readonly IWarehouseService _warehouseService;

        private readonly IContainerService _containerService;

        private readonly ISalesreturnsService _salesreturnsService;

        private readonly IOutSourcingWareHousingService _outSourcingWareHouseService;

        private readonly IMaterialRequisitionService _materialRequisitionService;

        public WarehouseManagementController(IWarehouseService warehouseService,IContainerService containerService, ISalesreturnsService salesreturnsService, IOutSourcingWareHousingService outSourcingWareHouseService, IMaterialRequisitionService materialRequisitionService)
        {
            _warehouseService = warehouseService;
            _containerService = containerService;
            _salesreturnsService = salesreturnsService;
            _outSourcingWareHouseService = outSourcingWareHouseService;
            _materialRequisitionService = materialRequisitionService;
        }

        #region 仓库设置
        /// <summary>
        /// 获取仓库设置信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIPage<Warehouse>> GetWarehousePageList([FromQuery]GeiWarehousePageListDTO request)
        {
            return await _warehouseService.GetWarehousePageList(request);
        }
        /// <summary>
        /// 新增仓库设置信息
        /// </summary>
        /// <param name="param">仓库设置参数</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> CreateWarehouse([FromBody] Warehouse param)
        {
            return await _warehouseService.CreateWarehouse(param);
        }

        /// <summary>
        /// 删除仓库设置信息
        /// </summary>
        /// <param name="param">仓库设置参数</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> DeleteWarehouse([FromBody] Warehouse param)
        {
            return await _warehouseService.DeleteWarehouse(param);
        }

        /// <summary>
        /// 修改仓库设置信息
        /// </summary>
        /// <param name="param">仓库设置参数</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> UpdateWarehouse([FromBody] Warehouse param)
        {
            return await _warehouseService.UpdateWarehouse(param);
        }

        #endregion

        #region 库区设置
        /// <summary>
        /// 获取库区设置信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIPage<ReservoirArea>> GetReservoirAreaPageList(GetReservoirAreaPageListDTO request)
        {
            return await _warehouseService.GetReservoirAreaPageList(request);
        }
        /// <summary>
        /// 新增库区设置信息
        /// </summary>
        /// <param name="param">库区设置参数</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> CreateReservoirArea([FromBody]ReservoirArea param)
        {
            return await _warehouseService.CreateReservoirArea(param);
        }

        /// <summary>
        /// 删除库区设置信息
        /// </summary>
        /// <param name="param">库区设置参数</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> DeleteReservoirArea([FromBody]ReservoirArea param)
        {
            return await _warehouseService.DeleteReservoirArea(param);
        }

        /// <summary>
        /// 修改库区设置信息
        /// </summary>
        /// <param name="param">库区设置参数</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> UpdateReservoirArea([FromBody]ReservoirArea param)
        {
            return await _warehouseService.UpdateReservoirArea(param);
        }

        #endregion

        #region 库位设置
        /// <summary>
        /// 获取库位设置信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIPage<BinLocation>> GetBinLocationPageList(GetBinLocationPageListDTO request)
        {
            return await _warehouseService.GetBinLocationPageList(request);
        }
        /// <summary>
        /// 新增库位设置信息
        /// </summary>
        /// <param name="param">库位设置参数</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> CreateBinLocation([FromBody]BinLocation param)
        {
            return await _warehouseService.CreateBinLocation(param);
        }

        /// <summary>
        /// 删除库位设置信息
        /// </summary>
        /// <param name="param">库位设置参数</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> DeleteBinLocation([FromBody] BinLocation param)
        {
            return await _warehouseService.DeleteBinLocation(param);
        }

        /// <summary>
        /// 修改库位设置信息
        /// </summary>
        /// <param name="param">库位设置参数</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> UpdateBinLocation([FromBody] BinLocation param)
        {
            return await _warehouseService.UpdateBinLocation(param);
        }
        #endregion

        #region 装箱管理

        /// <summary>
        /// 获取库位设置信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIPage<Container>> GetContainerPageList(GetContainerPageListDTO param)
        {
            return await _containerService.GetContainerPageList(param);
        }
        /// <summary>
        /// 新增库位设置信息
        /// </summary>
        /// <param name="param">库位设置参数</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> CreateContainer([FromBody]Container container)
        {
            return await _containerService.CreateContainer(container);
        }

        /// <summary>
        /// 删除库位设置信息
        /// </summary>
        /// <param name="param">库位设置参数</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> DeleteContainer([FromBody]Container param)
        {
            return await _containerService.DeleteContainer(param);
        }

        /// <summary>
        /// 修改库位设置信息
        /// </summary>
        /// <param name="param">库位设置参数</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> UpdateContainer([FromBody]Container param)
        {
            return await _containerService.UpdateContainer(param);
        }

        #endregion

        #region 销售退货

        /// <summary>
        /// 获取销售退货信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIPage<Salesreturns>> GetSalesreturnsList(GetSalesreturnsListDTO param)
        {
            return await _salesreturnsService.GetSalesreturnsList(param);
        }
        /// <summary>
        /// 新增销售退货信息
        /// </summary>
        /// <param name="param">销售退货参数</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> CreateSalesreturns(Salesreturns salesreturns)
        {
            return await _salesreturnsService.CreateSalesreturns(salesreturns);
        }

        /// <summary>
        /// 删除销售退货信息
        /// </summary>
        /// <param name="param">销售退货参数</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> DeleteSalesreturns(Salesreturns salesreturns)
        {
            return await _salesreturnsService.DeleteSalesreturns(salesreturns);
        }

        /// <summary>
        /// 修改销售退货信息
        /// </summary>
        /// <param name="param">销售退货参数</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> UpdateSalesreturns(Salesreturns salesreturns)
        {
            return await _salesreturnsService.UpdateSalesreturns(salesreturns);
        }

        #endregion

        #region 外协入库

        /// <summary>
        /// 获取外协入库信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIPage<OutSourcingWareHousing>> GetOutSourcingWareHousingList(GetOutSourcingWareHousingListDTO param)
        {
            return await _outSourcingWareHouseService.GetOutSourcingWareHousingList(param);
        }
        /// <summary>
        /// 新增外协入库信息
        /// </summary>
        /// <param name="param">外协入库参数</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> CreateOutSourcingWareHousing([FromBody]OutSourcingWareHousing salesreturns)
        {
            return await _outSourcingWareHouseService.CreateOutSourcingWareHousing(salesreturns);
        }

        /// <summary>
        /// 删除外协入库信息
        /// </summary>
        /// <param name="param">外协入库参数</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> DeleteOutSourcingWareHousing([FromBody]OutSourcingWareHousing salesreturns)
        {
            return await _outSourcingWareHouseService.DeleteOutSourcingWareHousing(salesreturns);
        }

        /// <summary>
        /// 修改外协入库信息
        /// </summary>
        /// <param name="param">外协入库参数</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> UpdateOutSourcingWareHousing([FromBody]OutSourcingWareHousing salesreturns)
        {
            return await _outSourcingWareHouseService.UpdateOutSourcingWareHousing(salesreturns);
        }

        /// <summary>
        /// 执行入库
        /// </summary>
        /// <param name="param">外协入库参数</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> ExecuteWarehousing([FromBody]OutSourcingWareHousing salesreturns)
        {
            return await _outSourcingWareHouseService.ExecuteWarehousing(salesreturns);
        }

        #endregion

        #region 生产领料

        /// <summary>
        /// 获取生产领料信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIPage<MaterialRequisition>> GetMaterialRequisitionList(GetMaterialRequisitionListDTO param)
        {
            return await _materialRequisitionService.GetMaterialRequisitionList(param);
        }
        /// <summary>
        /// 新增生产领料信息
        /// </summary>
        /// <param name="param">生产领料参数</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> CreateMaterialRequisition([FromBody]MaterialRequisition materialRequisition)
        {
            return await _materialRequisitionService.CreateMaterialRequisition(materialRequisition);
        }

        /// <summary>
        /// 删除生产领料信息
        /// </summary>
        /// <param name="param">生产领料参数</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> DeleteMaterialRequisition([FromBody]MaterialRequisition salesreturns)
        {
            return await _materialRequisitionService.DeleteMaterialRequisition(salesreturns);
        }

        /// <summary>
        /// 修改生产领料信息
        /// </summary>
        /// <param name="param">生产领料参数</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> UpdateMaterialRequisition([FromBody] MaterialRequisition salesreturns)
        {
            return await _materialRequisitionService.UpdateMaterialRequisition(salesreturns);
        }

        #endregion
    }
}
